#pragma once

#include "UMLActivityDiagram.h"

#include "../uml/Activity.h"

namespace uml {

const bool UMLActivityDiagram::isActivityFrame_default_ = false;
UMLActivityDiagram::UMLActivityDiagram(const QString& umlType)
    : UMLDiagram(umlType) {}

void UMLActivityDiagram::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLDiagram::fromJson(json, errorList);
    UMLBehaviorDiagram::fromJson(json, errorList);
    modelElement_ = JsonSerializable::create<Activity>(json.value("modelElement"), errorList);

    isActivityFrame_ = json.value("isActivityFrame").toBool(isActivityFrame_default_);
}

void UMLActivityDiagram::toJson(QJsonObject& json) {
    UMLDiagram::toJson(json);
    UMLBehaviorDiagram::toJson(json);
    if (modelElement_) {
        QJsonObject modelElement_json;
        modelElement_->toJson(modelElement_json);
        json.insert("modelElement", modelElement_json);
    }
    if (isActivityFrame_ != isActivityFrame_default_) {
        json.insert("isActivityFrame", isActivityFrame_);
    }
}

/// <summary>
/// modelElement getter
/// Restricts UMLActivityDiagrams to show Activities.
/// </summary>
shared_ptr<Activity> UMLActivityDiagram::modelElement() const {
    return modelElement_;
}

/// <summary>
/// modelElement setter
/// Restricts UMLActivityDiagrams to show Activities.
/// </summary>
void UMLActivityDiagram::setModelElement(shared_ptr<Activity> value) {
    modelElement_ = value;
}

/// <summary>
/// isActivityFrame getter
/// Indicates whether the UMLActivityDiagram shall be shown with a frame that is a
/// round-cornered rectangle without a pentagonal header.
/// </summary>
bool UMLActivityDiagram::isActivityFrame() const {
    return isActivityFrame_;
}

/// <summary>
/// isActivityFrame setter
/// Indicates whether the UMLActivityDiagram shall be shown with a frame that is a
/// round-cornered rectangle without a pentagonal header.
/// </summary>
void UMLActivityDiagram::setIsActivityFrame(bool value) {
    isActivityFrame_ = value;
}

} // namespace uml
